package com.itSession.cn.controller.app;

import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.itSession.cn.util.Result;
import com.itSession.cn.util.ResultGenerator;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.util.StringUtils;

import com.itSession.cn.entity.ScoreInfo;
import com.itSession.cn.mapper.ScoreInfoMapper;

/**
 * @ClassName: ScoreInfoController
 * @description: ScoreInfoController
 * @author: hanP
 * @create: 2023-04-07 09:27:28
 */
@Api(tags = " 成绩信息模块")
@RequestMapping("/scoreInfo")
@RestController
public class ScoreInfoController {

    @Autowired
    private ScoreInfoMapper scoreInfoMapper;

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @ApiOperation(value = "查询所有记录", httpMethod = "POST", notes = "加载数据", response = Result.class)
    @RequestMapping("list")
    public Result listAll() {
    	try {
    		List<ScoreInfo> list = scoreInfoMapper.listAll();
            return ResultGenerator.genSuccessResult(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genErrorResult(500,e.getMessage());
        }
    }

    @ApiOperation(value = "查询所有记录", httpMethod = "POST", notes = "加载数据", response = Result.class)
    @RequestMapping("listByScoreUname")
    public Result listByScoreUname(String scoreUname) {
        try {
            List<ScoreInfo> list = scoreInfoMapper.listByScoreUname(scoreUname);
            return ResultGenerator.genSuccessResult(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genErrorResult(500,e.getMessage());
        }
    }



    /**
     * 分页查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @ApiOperation(value = "查询所有记录", httpMethod = "POST", notes = "加载数据", response = Result.class)
    @RequestMapping("listByParam")
    public Result listByParam(String keyword) {
    	try {
         	Map<String, Object> map = new HashMap<>();
            map.put("keyword",keyword);
    		List<ScoreInfo> list = scoreInfoMapper.listByParam(map);
            return ResultGenerator.genSuccessResult(list);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genErrorResult(500,e.getMessage());
        }
    }



    /**
     * 根据主键查询
     *
     * @param scoreId 主键
     * @return 返回记录，没有返回null
     */
    @ApiOperation(value = "根据主键查询", httpMethod = "POST", notes = "加载数据", response = ScoreInfo.class)
     @ApiImplicitParams({
            @ApiImplicitParam(name = "scoreId", value = "", required = false, paramType = "query" ,dataType="int")
    })
    @RequestMapping("getById")
    public Result getById(@ApiIgnore Integer scoreId) {
    	try {
    	 	ScoreInfo scoreInfo = scoreInfoMapper.getById(scoreId);
         	return ResultGenerator.genSuccessResult(scoreInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genErrorResult(500, e.getMessage());
        }
       
    }
    
    
    /**
     * 新增，忽略null字段
     *
     * @param scoreInfo 新增的记录
     * @return 返回影响行数
     */
      @ApiOperation(value = "新增，忽略null字段", httpMethod = "POST", notes = "加载数据", response = Result.class)
    @ApiImplicitParams({
                @ApiImplicitParam(name = "scoreId", value = "", required = false, paramType = "query" ,dataType="int"),
                @ApiImplicitParam(name = "scoreName", value = "学科", required = false, paramType = "query" ,dataType="string"),
                @ApiImplicitParam(name = "scoreResult", value = "得分", required = false, paramType = "query" ,dataType="string"),
                @ApiImplicitParam(name = "scoreUname", value = "学生姓名", required = false, paramType = "query" ,dataType="string"),
                @ApiImplicitParam(name = "scoreUclass", value = "班级", required = false, paramType = "query" ,dataType="string"),
        })
    @RequestMapping("insertIgnoreNull")
    public Result insertIgnoreNull(@ApiIgnore ScoreInfo scoreInfo) {
    	try {
    		scoreInfoMapper.insertIgnoreNull(scoreInfo);
            return ResultGenerator.genSuccessResult();
       } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genErrorResult(500,e.getMessage());
        }
    }
    
    
    /**
     * 修改，忽略null字段
     *
     * @param scoreInfo 修改的记录
     * @return 返回影响行数
     */
    @ApiOperation(value = "修改，忽略null字段", httpMethod = "POST", notes = "加载数据", response = Result.class)
    @ApiImplicitParams({
                @ApiImplicitParam(name = "scoreId", value = "", required = false, paramType = "query" ,dataType="int"),
                @ApiImplicitParam(name = "scoreName", value = "学科", required = false, paramType = "query" ,dataType="string"),
                @ApiImplicitParam(name = "scoreResult", value = "得分", required = false, paramType = "query" ,dataType="string"),
                @ApiImplicitParam(name = "scoreUname", value = "学生姓名", required = false, paramType = "query" ,dataType="string"),
                @ApiImplicitParam(name = "scoreUclass", value = "班级", required = false, paramType = "query" ,dataType="string"),
        })
    @RequestMapping("updateIgnoreNull")
    public Result updateIgnoreNull(@ApiIgnore ScoreInfo scoreInfo) {
    	 try {
         	 scoreInfoMapper.updateIgnoreNull(scoreInfo);
            return ResultGenerator.genSuccessResult();
         } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genErrorResult(500,e.getMessage());
        }
    }
    
    
     /**
     * 删除记录
     *
     * @param scoreInfo 待删除的记录
     */
    @ApiOperation(value = "删除记录", httpMethod = "POST", notes = "加载数据", response = Result.class)
    @RequestMapping("delete")
    public Result delete(@ApiIgnore ScoreInfo scoreInfo) {
    	 try {
         	 scoreInfoMapper.delete(scoreInfo);
             return ResultGenerator.genSuccessResult();
         } catch (Exception e) {
            e.printStackTrace();
            return ResultGenerator.genErrorResult(500,e.getMessage());
        }
    }
    
   
    
}